<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增图书信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-bookinfo-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">图书名称：</label>
                <div class="col-sm-8">
                    <input name="bookName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">作者：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="authorId" name="authorId" type="hidden" class="form-control" />
                        <input id="authorName" name="authorName" class="form-control" type="text" onclick="selectAuthor()" readonly="true"  required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">出版社：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="publishId" name="publishId" type="hidden" class="form-control" />
                        <input id="publishName" name="publishName" class="form-control" type="text" onclick="selectPublish()" readonly="true"  required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">图书简介：</label>
                <div class="col-sm-8">
                    <textarea name="descption" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">图片路径：</label>
                <div class="col-sm-8">
                    <input name="file" class="form-control" type="file" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">分类目录：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="indexId" name="indexId" type="hidden" class="form-control" />
                        <input id="indexName" name="indexName" class="form-control" type="text" onclick="selectIndexmenuTree()" readonly="true"  required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">折扣价：</label>
                <div class="col-sm-8">
                    <input name="discountPrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否作者亲签版：</label>
                <div class="col-sm-8">
                    <select name="isSign" class="form-control m-b" th:with="type=${@dict.getType('dg_true_or_false')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />

    <!--引入axios框架-->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

    <script th:inline="javascript">
        var prefix = ctx + "gzbook/bookinfo"
        $("#form-bookinfo-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                // $.operate.save(prefix + "/add", $('#form-bookinfo-add').serialize());
                $.operate.mysave(prefix + "/add");
            }
        }


        /*作者管理-新增-选择作者*/
        function selectAuthor() {
            var authorId = $("#authorId").val();
            authorId = 1;
            var url = ctx + "gzbook/authorinfo/selectAuthor/" + authorId ;
            var options = {
                title: '作者选择',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#authorId").val(body.find('#treeId').val());
            $("#authorName").val(body.find('#authorName').val());
            $.modal.close(index);
        }


        /*作者管理-新增-选择作者*/
        function selectPublish() {
            var publishId = $("#publishId").val();
            publishId = 1;
            var url = ctx + "gzbook/publishinfo/selectpublish/" + publishId ;
            var options = {
                title: '出版社选择',
                width: "380",
                url: url,
                callBack: doSubmitP
            };
            $.modal.openOptions(options);
        }

        function doSubmitP(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#publishId").val(body.find('#treeId').val());
            $("#publishName").val(body.find('#publishName').val());
            $.modal.close(index);
        }

        /*图书分类类目-新增-选择父图书分类类目树*/
        function selectIndexmenuTree() {
            var options = {
                title: '图书分类类目选择',
                width: "380",
                url: ctx + "gzbook/indexmenu/selectIndexmenuTree/" + $("#indexId").val(),
                callBack: doSubmitT
            };
            $.modal.openOptions(options);
        }

        function doSubmitT(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#indexId").val(body.find('#treeId').val());
            $("#indexName").val(body.find('#treeName').val());
            $.modal.close(index);
        }



    </script>
</body>
</html>